package com.briup.UserBuyGoods.one;


import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

public class UserBuyGoodsList {
    public static class UserBuyGoodsListMapper
                    extends Mapper<LongWritable, Text,Text,Text>{
        @Override
        protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
            String[] strs = value.toString().split(",");
            context.write(new Text(strs[0]),new Text(strs[1]));
        }
    }
    public static class UserBuyGoodsListReducer
                    extends Reducer<Text,Text,Text,Text>{
        StringBuffer sb=new StringBuffer();
        @Override
        protected void reduce(Text key, Iterable<Text> values, Context context) throws IOException, InterruptedException {
            for (Text t:values){
                sb.append(t.toString()).append(",");
            }
            sb.setLength(sb.length()-1);
            context.write(key,new Text(sb.toString()));
            sb.setLength(0);
        }
    }
}
